package com.delu.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.CouponType;
import com.delu.mapper.CouponTypesMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.awt.*;
import java.util.List;

@RestController
@RequestMapping("couponType")
@Api("优惠券类型管理")
public class CouponTypeController {
    @Resource
    private CouponTypesMapper couponTypesMapper;

    @GetMapping
    @ApiOperation("优惠券类型查询")
    @ApiImplicitParam(name = "couponType",value = "优惠券ID",required = true,paramType = "query")
    public Result selectCouponType(@RequestParam("couponType")Integer couponType){
        System.out.println("优惠券信息" + couponType);
        CouponType couponType1 = couponTypesMapper.selectById(couponType);
        return Result.response(ResultEnum.SUCCESS).setData(couponType1);
    }

    @PostMapping
    @ApiOperation("优惠卷的增加")
    @ApiImplicitParam(name = "CouponType",value = "优惠券的实体类",required = true,paramType = "body")
    public Result insertCouponType(@RequestBody CouponType couponType){
        CouponType couponType1 = JSONObject.parseObject(JSON.toJSONString(couponType), CouponType.class);
        Integer i = couponTypesMapper.insert(couponType1);
        System.out.println("优惠券信息" + couponType);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @DeleteMapping
    @ApiOperation("优惠券的删除")
    @ApiImplicitParam(name = "couponType",value = "优惠券ID",required = true,paramType = "query")
    public Result deleteCouponType(@RequestParam("couponType")Integer couponType){
        System.out.println("优惠券信息" + couponType);
        int i = couponTypesMapper.deleteById(couponType);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }
}
